import logging

_logger = logging.getLogger('tyuo.identification')

__BASEPATH = "./" #This should be specified through configuration or automatic resolution

_LANGUAGES = []

def list_languages():
    return [name for (name, _) in _LANGUAGES]
    
def identify_language(line):
    best = None
    for (language, processor) in _LANGUAGES:
        (score, words) = processor.query(line)
        if not best or score > best[1]:
            best = (language, score, words)
        if score == 1.0: #perfect match
            break
    return best
    
if True: #If configuration states that English is supported
    try:
        cimport _european
        _LANGUAGES.append('en', _european.Processor(__BASEPATH + 'en.dict'))
    except Exception as e:
        _logger.error("Unable to load English identification sybsystem: {error}".format(
         error=e,
        ))
        
_LANGUAGES = tuple(_LANGUAGES)
